using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPRRABBON
    {
        public DataRow Convert2PRRABBON(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPRRABBON(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PRBMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PRBSTDBON"] = " ".PadRight(8 ); 
         dwReturn["PRBKOLL"] = " ".PadRight(5 ); 
         dwReturn["PRBART"] = " ".PadRight(24 ); 
         dwReturn["PRBBONVON"] = " ".PadRight(8 ); 
         dwReturn["PRBBONIN"] = " ".PadRight(8 ); 
         dwReturn["PRBBONBIS"] = " ".PadRight(8 ); 
         dwReturn["PRBBONLDAT"] = " ".PadRight(8 ); 
         dwReturn["PRBBONABRKZ"] = " ".PadRight(1 ); 
         dwReturn["PRBBONWE01"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP01"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE02"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP02"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE03"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP03"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE04"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP04"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE05"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP05"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE06"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP06"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE07"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP07"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE08"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP08"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE09"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP09"] = " ".PadRight(4 ); 
         dwReturn["PRBBONWE10"] = " ".PadRight(9 ); 
         dwReturn["PRBBONP10"] = " ".PadRight(4 ); 
         dwReturn["PRBGABONP"] = " ".PadRight(4 ); 
         dwReturn["PRBGBABRKZ"] = " ".PadRight(1 ); 
         dwReturn["PRBFIXBONP"] = " ".PadRight(4 ); 
         dwReturn["PRBFBABRKZ"] = " ".PadRight(1 ); 
         dwReturn["PRBVBONLDAT"] = " ".PadRight(8 ); 
         dwReturn["PRBVORBONP"] = " ".PadRight(4 ); 
         dwReturn["PRBVBABRKZ"] = " ".PadRight(1 ); 
         dwReturn["PRBVORBONV"] = " ".PadRight(12 ); 
         dwReturn["PRBAENDZL"] = " ".PadRight(3 ); 
         dwReturn["PRBAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["PRBAENDDAT"] = " ".PadRight(6 ); 
         dwReturn["PRBNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["PRBNEUDAT"] = " ".PadRight(6 ); 
         dwReturn["PRBBASIS"] = " ".PadRight(1 ); 
         dwReturn["PRBSPLITT"] = " ".PadRight(1 ); 
         dwReturn["PRBMEEH"] = " ".PadRight(3 ); 
         dwReturn["PRFILLER"] = " ".PadRight(63 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPRRABBON(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePRRABBON(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPRRABBON(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPRRABBON(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPRRABBON(dwLocal, ITXDBVERSION);
            }
            UpdatePRRABBON(dwLocal);
        }
        public void InsertPRRABBON(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PRRABBON(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPRRABBON(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PRRABBON WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PRRABBON  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PRRABBON";
            Return = Result;
            return Return;
        }
        public void DeletePRRABBON(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PRRABBON   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePRRABBON(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PRRABBON SET "
                    +"PRBMANDANT= :PRBMANDANT,"
                    +"PRBSTDBON= :PRBSTDBON,"
                    +"PRBKOLL= :PRBKOLL,"
                    +"PRBART= :PRBART,"
                    +"PRBBONVON= :PRBBONVON,"
                    +"PRBBONIN= :PRBBONIN,"
                    +"PRBBONBIS= :PRBBONBIS,"
                    +"PRBBONLDAT= :PRBBONLDAT,"
                    +"PRBBONABRKZ= :PRBBONABRKZ,"
                    +"PRBBONWE01= :PRBBONWE01,"
                    +"PRBBONP01= :PRBBONP01,"
                    +"PRBBONWE02= :PRBBONWE02,"
                    +"PRBBONP02= :PRBBONP02,"
                    +"PRBBONWE03= :PRBBONWE03,"
                    +"PRBBONP03= :PRBBONP03,"
                    +"PRBBONWE04= :PRBBONWE04,"
                    +"PRBBONP04= :PRBBONP04,"
                    +"PRBBONWE05= :PRBBONWE05,"
                    +"PRBBONP05= :PRBBONP05,"
                    +"PRBBONWE06= :PRBBONWE06,"
                    +"PRBBONP06= :PRBBONP06,"
                    +"PRBBONWE07= :PRBBONWE07,"
                    +"PRBBONP07= :PRBBONP07,"
                    +"PRBBONWE08= :PRBBONWE08,"
                    +"PRBBONP08= :PRBBONP08,"
                    +"PRBBONWE09= :PRBBONWE09,"
                    +"PRBBONP09= :PRBBONP09,"
                    +"PRBBONWE10= :PRBBONWE10,"
                    +"PRBBONP10= :PRBBONP10,"
                    +"PRBGABONP= :PRBGABONP,"
                    +"PRBGBABRKZ= :PRBGBABRKZ,"
                    +"PRBFIXBONP= :PRBFIXBONP,"
                    +"PRBFBABRKZ= :PRBFBABRKZ,"
                    +"PRBVBONLDAT= :PRBVBONLDAT,"
                    +"PRBVORBONP= :PRBVORBONP,"
                    +"PRBVBABRKZ= :PRBVBABRKZ,"
                    +"PRBVORBONV= :PRBVORBONV,"
                    +"PRBAENDZL= :PRBAENDZL,"
                    +"PRBAENDBEN= :PRBAENDBEN,"
                    +"PRBAENDDAT= :PRBAENDDAT,"
                    +"PRBNEUBEN= :PRBNEUBEN,"
                    +"PRBNEUDAT= :PRBNEUDAT,"
                    +"PRBBASIS= :PRBBASIS,"
                    +"PRBSPLITT= :PRBSPLITT,"
                    +"PRBMEEH= :PRBMEEH,"
                    +"PRFILLER= :PRFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PRBMANDANT", OracleType.NVarChar).Value = dwData["PRBMANDANT"].ToString(); 
          or1.Parameters.Add("PRBSTDBON", OracleType.NVarChar).Value = dwData["PRBSTDBON"].ToString(); 
          or1.Parameters.Add("PRBKOLL", OracleType.NVarChar).Value = dwData["PRBKOLL"].ToString(); 
          or1.Parameters.Add("PRBART", OracleType.NVarChar).Value = dwData["PRBART"].ToString(); 
          or1.Parameters.Add("PRBBONVON", OracleType.NVarChar).Value = dwData["PRBBONVON"].ToString(); 
          or1.Parameters.Add("PRBBONIN", OracleType.NVarChar).Value = dwData["PRBBONIN"].ToString(); 
          or1.Parameters.Add("PRBBONBIS", OracleType.NVarChar).Value = dwData["PRBBONBIS"].ToString(); 
          or1.Parameters.Add("PRBBONLDAT", OracleType.NVarChar).Value = dwData["PRBBONLDAT"].ToString(); 
          or1.Parameters.Add("PRBBONABRKZ", OracleType.NVarChar).Value = dwData["PRBBONABRKZ"].ToString(); 
          or1.Parameters.Add("PRBBONWE01", OracleType.NVarChar).Value = dwData["PRBBONWE01"].ToString(); 
          or1.Parameters.Add("PRBBONP01", OracleType.NVarChar).Value = dwData["PRBBONP01"].ToString(); 
          or1.Parameters.Add("PRBBONWE02", OracleType.NVarChar).Value = dwData["PRBBONWE02"].ToString(); 
          or1.Parameters.Add("PRBBONP02", OracleType.NVarChar).Value = dwData["PRBBONP02"].ToString(); 
          or1.Parameters.Add("PRBBONWE03", OracleType.NVarChar).Value = dwData["PRBBONWE03"].ToString(); 
          or1.Parameters.Add("PRBBONP03", OracleType.NVarChar).Value = dwData["PRBBONP03"].ToString(); 
          or1.Parameters.Add("PRBBONWE04", OracleType.NVarChar).Value = dwData["PRBBONWE04"].ToString(); 
          or1.Parameters.Add("PRBBONP04", OracleType.NVarChar).Value = dwData["PRBBONP04"].ToString(); 
          or1.Parameters.Add("PRBBONWE05", OracleType.NVarChar).Value = dwData["PRBBONWE05"].ToString(); 
          or1.Parameters.Add("PRBBONP05", OracleType.NVarChar).Value = dwData["PRBBONP05"].ToString(); 
          or1.Parameters.Add("PRBBONWE06", OracleType.NVarChar).Value = dwData["PRBBONWE06"].ToString(); 
          or1.Parameters.Add("PRBBONP06", OracleType.NVarChar).Value = dwData["PRBBONP06"].ToString(); 
          or1.Parameters.Add("PRBBONWE07", OracleType.NVarChar).Value = dwData["PRBBONWE07"].ToString(); 
          or1.Parameters.Add("PRBBONP07", OracleType.NVarChar).Value = dwData["PRBBONP07"].ToString(); 
          or1.Parameters.Add("PRBBONWE08", OracleType.NVarChar).Value = dwData["PRBBONWE08"].ToString(); 
          or1.Parameters.Add("PRBBONP08", OracleType.NVarChar).Value = dwData["PRBBONP08"].ToString(); 
          or1.Parameters.Add("PRBBONWE09", OracleType.NVarChar).Value = dwData["PRBBONWE09"].ToString(); 
          or1.Parameters.Add("PRBBONP09", OracleType.NVarChar).Value = dwData["PRBBONP09"].ToString(); 
          or1.Parameters.Add("PRBBONWE10", OracleType.NVarChar).Value = dwData["PRBBONWE10"].ToString(); 
          or1.Parameters.Add("PRBBONP10", OracleType.NVarChar).Value = dwData["PRBBONP10"].ToString(); 
          or1.Parameters.Add("PRBGABONP", OracleType.NVarChar).Value = dwData["PRBGABONP"].ToString(); 
          or1.Parameters.Add("PRBGBABRKZ", OracleType.NVarChar).Value = dwData["PRBGBABRKZ"].ToString(); 
          or1.Parameters.Add("PRBFIXBONP", OracleType.NVarChar).Value = dwData["PRBFIXBONP"].ToString(); 
          or1.Parameters.Add("PRBFBABRKZ", OracleType.NVarChar).Value = dwData["PRBFBABRKZ"].ToString(); 
          or1.Parameters.Add("PRBVBONLDAT", OracleType.NVarChar).Value = dwData["PRBVBONLDAT"].ToString(); 
          or1.Parameters.Add("PRBVORBONP", OracleType.NVarChar).Value = dwData["PRBVORBONP"].ToString(); 
          or1.Parameters.Add("PRBVBABRKZ", OracleType.NVarChar).Value = dwData["PRBVBABRKZ"].ToString(); 
          or1.Parameters.Add("PRBVORBONV", OracleType.NVarChar).Value = dwData["PRBVORBONV"].ToString(); 
          or1.Parameters.Add("PRBAENDZL", OracleType.NVarChar).Value = dwData["PRBAENDZL"].ToString(); 
          or1.Parameters.Add("PRBAENDBEN", OracleType.NVarChar).Value = dwData["PRBAENDBEN"].ToString(); 
          or1.Parameters.Add("PRBAENDDAT", OracleType.NVarChar).Value = dwData["PRBAENDDAT"].ToString(); 
          or1.Parameters.Add("PRBNEUBEN", OracleType.NVarChar).Value = dwData["PRBNEUBEN"].ToString(); 
          or1.Parameters.Add("PRBNEUDAT", OracleType.NVarChar).Value = dwData["PRBNEUDAT"].ToString(); 
          or1.Parameters.Add("PRBBASIS", OracleType.NVarChar).Value = dwData["PRBBASIS"].ToString(); 
          or1.Parameters.Add("PRBSPLITT", OracleType.NVarChar).Value = dwData["PRBSPLITT"].ToString(); 
          or1.Parameters.Add("PRBMEEH", OracleType.NVarChar).Value = dwData["PRBMEEH"].ToString(); 
          or1.Parameters.Add("PRFILLER", OracleType.NVarChar).Value = dwData["PRFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
